/*
 *  $Id: IcyVeil.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Water.Spells {
    public class IcyVeil: TargetEnchantmentCard<Creature> {
        public IcyVeil(): base("001_w_s_icy_veil") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Water;
            Value = 100;
            Target = CreatureTarget.Own;
            AddManaCost(ElementType.Water, 5);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new IcyVeilAffect();
        }

        private class IcyVeilAffect: EnchantmentAffect<IcyVeil> {
            public override void SetAffect() {
                base.SetAffect();
                LocalSummary.OnOffenceReady += DoBattle;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                LocalSummary.OnOffenceReady -= DoBattle;
            }

            private void DoBattle(Creature attacker) {
                if (attacker.Defenders.Count != 0) {
                    foreach (Creature cr in attacker.Owner.Enemy.GetCreatures())
                        if (attacker.DistanceTo(cr) <= 1)
                            cr.DamageBy(NewDamage(DamageType.MagicAttack, 2));
                }
            }
        }
    }
}
